<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Full Layout - jQuery EasyUI Demo</title>
	<#include "./../common/header.html"/>
</head>
<body class="easyui-layout">
	<table id="dg" class="easyui-datagrid" title="定时报警策略" style="width:100%;height:98%"
			data-options="
				iconCls: 'icon-ok',
				singleSelect: true,
				toolbar: '#tb',
				url:'${ctx}/pattern/loadJobPattern'
			">
		<thead>
			<tr>
				<th data-options="field:'patternName',width:100">名称</th>
				<th data-options="field:'pattern',width:250">匹配规则</th>
<!-- 				<th data-options="field:'mobile',width:100">报警接收手机</th> -->
				<th data-options="field:'email',width:200">email</th>
			</tr>
		</thead>
	</table>
	<div id="tb" style="height:auto">
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="add_dlg()">添加规则</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" onclick="deleteRows()">删除规则</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="editRows()">查看规则</a>
	</div>

	<div id="add_dlg" class="easyui-dialog" closed="true" data-options="width:500,height:300">
		<div style="padding:10px 60px 20px 60px">
			<form id="ff" method="post" action="${ctx}/pattern/addJobPattern">
				<table cellpadding="10" width="100%">
					<tr>
						<td>名称</td>
						<td><input class="easyui-textbox" type="text" name="patternName" data-options="required:true" style="width:200px"></input></td>
					</tr>
					<tr>
						<td>错误匹配规则（正则）:</td>
						<td><input class="easyui-textbox" type="text" name="pattern" data-options="required:true" style="width:200px;height:50px;"></input></td>
					</tr>
					<tr>
						<td>报警邮件:</td>
						<td>
						<input type="hidden" name="_id"/>
						<input class="easyui-textbox" type="text" name="email" data-options="required:true" style="width:200px"></input></td>
					</tr>
<!-- 					<tr> -->
<!-- 						<td>报警手机:</td> -->
<!-- 						<td><input class="easyui-textbox" type="text" name="mobile" data-options="validType:'mobile'" style="width:200px"></input></td> -->
<!-- 					</tr> -->
				</table>
			</form>
		</div>
	</div>
					
</body>

<script>
function add_dlg(){
	$('#add_dlg').dialog({
		title:'添加定时报警策略',
		closed: false,
		cache: false,
		buttons:[{ 
			text:'提交', 
			iconCls:'icon-ok',
		
			handler:function(){
				$("#add_dlg").find('#ff').form('submit',{
					onSubmit:function(){
					var flag = $(this).form('validate');
						return flag;
					},
					dataType:"json",
					success : function(response) {
						if(response=='true'){
							$.messager.alert({
								title : '提示',
								msg : "操作成功"
							});
						}
					
						$('#add_dlg').dialog('close');
						$('#dg').datagrid('reload'); 
					}
				});
				
			} 
		},{ 
			text:'关闭', 
			handler:function(){ 
				$('#add_dlg').dialog('close');
			} 
		}], 
		onOpen:function(){ 
			//$('#add_contentt_dlg_{$rbtId}').dialog('refresh', '__URL__/toAddInfoForm&rbtId={$rbtId}'); 
		} 
	});
	
}
function deleteRows(){
	var row = $("#dg").datagrid('getSelected'); 
	if(row!=null){
		$.messager.confirm('删除?', '确认删除?', function(r){
			if(r){
				$.ajax({ url: "${ctx}/pattern/delJobPattern?id="+row._id, success: function(response){
					var data= $.parseJSON(response); 
					if(response==true){
						$("#dg").datagrid('reload');
					}
					$.messager.alert({
						title : '提示',
						msg : "操作成功"
					});
				}});
			}

		});
	
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
}

function editRows(){
	var row = $("#dg").datagrid('getSelected'); 
	if(row!=null){
		$('#ff').form('load',row);
		$('#add_dlg').dialog({
			title:'查看详情',
			closed: false,
			cache: false,
			buttons:[{ 
				text:'关闭', 
				handler:function(){ 
					$('#add_dlg').dialog('close');
				} 
			}] 
		});
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
	
}
</script>
</html>